cmake_minimum_required(VERSION 3.16)

project(itetest VERSION 0.1 LANGUAGES CXX)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets Network)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Network)
find_package(Qt6 REQUIRED COMPONENTS HttpServer)


include_directories(${CMAKE_CURRENT_SOURCE_DIR}/3pp/zlgcan_x64
                    ${CMAKE_CURRENT_SOURCE_DIR}/3pp/dbc
                    ${CMAKE_CURRENT_SOURCE_DIR}/framework/
                    ${CMAKE_CURRENT_SOURCE_DIR}/playback/
                    ${CMAKE_CURRENT_SOURCE_DIR}/DbcLoader/include
                    ${CMAKE_CURRENT_SOURCE_DIR}/3pp/
                    ${CMAKE_CURRENT_SOURCE_DIR}/networkservice/)

link_directories(${CMAKE_CURRENT_SOURCE_DIR}/3pp/zlgcan_x64
                ${CMAKE_CURRENT_SOURCE_DIR}/3pp/dbc/x64)

file(GLOB FRAMEWORK_SRC  ${CMAKE_CURRENT_SOURCE_DIR}/framework/*)
file(GLOB DBC_SRC  ${CMAKE_CURRENT_SOURCE_DIR}/DbcLoader/include/*)
file(GLOB PLAYBACK_SRC  ${CMAKE_CURRENT_SOURCE_DIR}/playback/*)

set(PROJECT_SOURCES
        main.cpp
        mainwindow.cpp
        mainwindow.h
        mainwindow.ui
        ${FRAMEWORK_SRC}
        ${DBC_SRC}
        ${PLAYBACK_SRC}
)

qt_add_executable(itetest
    MANUAL_FINALIZATION
    ${PROJECT_SOURCES}
    ./networkservice/multiscreen.cpp
    ./networkservice/logupload.h networkservice/logupload.cpp
)

target_link_libraries(itetest PRIVATE Qt${QT_VERSION_MAJOR}::Widgets zlgcan zdbc can_dbc_loader)
target_link_libraries(itetest PRIVATE Qt6::HttpServer)

# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
# If you are developing for iOS or macOS you should consider setting an
# explicit, fixed bundle identifier manually though.
if(${QT_VERSION} VERSION_LESS 6.1.0)
  set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.itetest)
endif()
set_target_properties(itetest PROPERTIES
    ${BUNDLE_ID_OPTION}
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE TRUE
)

include(GNUInstallDirs)
install(TARGETS itetest
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

if(QT_VERSION_MAJOR EQUAL 6)
    qt_finalize_executable(itetest)
endif()

add_subdirectory(DbcLoader)
